require("Relationship")
require("Sensibility")

function UnitTests:testTellAction()

	local stage =
	{
		Rooms =
		{
			Room1 =
			{			
			},
			
			Room2 =
			{	
			}			
		},
		
		Doors =
		{
			{
				Rooms = 
				{
					"Room1",
					"Room2"
				},
			}
		}		
	}
	
	local cast =
	{
		Player =
		{
			initialLocation = "Room1"
		},
		
		Bots =
		{
			Bot1 =
			{
			}
		}
	}
	
	local game = Game:new(stage, cast)
	
	local room1 = gField.entityTypes.Location.Room1
	local room2 = gField.entityTypes.Location.Room2
	local bot1 = gField.entityTypes.Mind.Bot1
			
	gRandom:addContextualBias({"Body", "Bot1Body", "CurrentContainer"}, room2)

	assert(bot1.body)
	assert(not bot1.body:isPropertyCollasped("CurrentContainer"))
	
	gGame:start()
	
	assert(bot1.body:isPropertyCollasped("CurrentContainer"))
	assert(bot1.body:getCollapsedProperty("CurrentContainer") == room2)
		
	gPlayer.body:execute("moveTo", room2)
	gGame:onBeat()
	
	local relationship = Relationship:new("Bot1LovePlayer", bot1, gPlayer)
	gRandom:addContextualBias({"Relationship", "Bot1LovePlayer", "EnablingSteps"}, 2)
	
	local sensibilityCause = Sentence:new()
	sensibilityCause:setSubject(gPlayer)
	sensibilityCause:setVerb("look")
	sensibilityCause:setDirectObject(bot1)
	local sensibility = Sensibility:new(sensibilityCause, relationship, 1, 1)
	bot1:addSensibility(sensibility)

	sensibilityCause = Sentence:new()
	sensibilityCause:setSubject(gPlayer)
	sensibilityCause:setVerb("kiss")
	sensibilityCause:setDirectObject(bot1)
	sensibility = Sensibility:new(sensibilityCause, relationship, 3, 3)
	bot1:addSensibility(sensibility)
	
	local belief = Sentence:new()
	belief:setSubject(bot1)
	belief:setVerb("punch")
	belief:setDirectObject(gPlayer)
	gPlayer:addBelief(belief, true)
	
	belief = Sentence:new()
	belief:setSubject(gPlayer)
	belief:setVerb("kiss")
	belief:setDirectObject(bot1)
	gPlayer:addBelief(belief, true)

	gPlayer:sensePossibleActions()
		
	assert(gPlayer.possibleActionDirectory.tell)
	assert(
		tostring(gPlayer.possibleActionDirectory.tell[1]) ==
		"snt{ < Body:PlayerBody [ tell doj( snt{ < Player:Player [ kiss doj( Bot:Bot1 ) ] > } ) ioj( Bot:Bot1 ) ] > }"
	)
	assert(
		tostring(gPlayer.possibleActionDirectory.tell[2]) ==
		"snt{ < Body:PlayerBody [ tell doj( snt{ < Bot:Bot1 [ punch doj( Player:Player ) ] > } ) ioj( Bot:Bot1 ) ] > }"
	)
	
	gPlayer.body:execute(gPlayer.possibleActionDirectory.tell[2])
	
	assert(not relationship:isPropertyCollasped("EnablingSteps"))
	
	gPlayer.body:execute(gPlayer.possibleActionDirectory.tell[1])
	
	assert(relationship:isPropertyCollasped("EnablingSteps"))
	assert(relationship:getCollapsedProperty("EnablingSteps") == 5)
end